<?php
session_start();
require('conn.php');
require('functions.php');
if($_SESSION['login']==1){
	_location("ucenter.php",301);
	exit;
}

$currentTime = time();
$changeTime = 5*60;
$rand = '';
if(isset($_SESSION['time'])) {
   if(($currentTime - $_SESSION['time']) >= $changeTime) {
        $_SESSION['time'] = $currentTime;
          $rand = mt_rand(1111, 9999);
          $_SESSION['yzm1'] = $rand;
   }else{
           $rand = $_SESSION['yzm1'];
   }
}else{
    $_SESSION['time'] = $currentTime;
    $rand = mt_rand(1111, 9999);
    $_SESSION['yzm1'] = $rand;
}
// var_dump($_SESSION['yzm1']);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
<title>找回密码</title>
<meta name="keywords" content="<?php echo $config['sitename']?>,登录" />
<meta name="description" content="<?php echo $config['sitename']?>用户登录。">
<script type="text/javascript" src="<?php echo $site?>/static/jquery.js"></script>
<link href="<?php echo $site?>/static/all.css" type="text/css" rel="stylesheet" media="all">
<style>
input::-webkit-input-placeholder, textarea::-webkit-input-placeholder { 
    color:    #6b6b6b;
}
input:-moz-placeholder, textarea:-moz-placeholder { 
    color:    #6b6b6b;
}
input::-moz-placeholder, textarea::-moz-placeholder { 
    color:    #6b6b6b;
}
input:-ms-input-placeholder, textarea:-ms-input-placeholder { 
    color:    #6b6b6b;
}
body{margin:0;}
.none{background: none;}
*{box-sizing:border-box;}
.bg{background: url('static/images/bg.png') center center;-webkit-background-size: 100px 100px;background-size: 100px 100px;-moz-background-size: 100px 100px;}
input{font-size: 16px;line-height: 1.25em;outline: 0px none;text-decoration: none;margin:0;}
</style>
<script type="text/javascript">
$(document).ready(function(){
  var InterValObj; //timer变量，控制时间
  var count = 5; //间隔函数，1秒执行
  var curCount=60;//当前剩余秒数  
  
  $("#btnSendCode2").click(function(){
  var phone=document.getElementById("pw-phone").value; 
  // var _code = document.getElementById('code').value;
  if (!phone.match(/^(((1[3|4|5|7|8][0-9]{1}))+\d{8})$/)) {
    alert("手机号不正确");
    document.getElementById('pw-phone').focus();
    return;
  }
  var ifrm = document.getElementsByName('iframe')[0];  
  ifrm = document.getElementById('iframe');  
  ifrm.src = 'reg_yzm.php?is_find=1&phone='+phone;
  $("#btnSendCode2").attr("disabled", "true");
  $("#btnSendCode2").val("请在" + curCount + "秒内输入验证码");
  InterValObj = window.setInterval(SetRemainTime, 1000); //启动计时器，1秒执行一次 
  });
 //timer处理函数
function SetRemainTime() {
      if (curCount == 0) {                
        window.clearInterval(InterValObj);//停止计时器
        $("#btnSendCode2").removeAttr("disabled");//启用按钮
        $("#btnSendCode2").val("重新发送验证码");
        curCount=60;
      }
      else {
        curCount--;
        $("#btnSendCode2").val("(" + curCount + "秒)");
      }
    }
});   
</script> 
</head>

<body class="bg">
<iframe name="iframe" style="display: none" id="iframe"></iframe>  
<div class="common-wrapper" style="background:none">
	<div class="main" style="padding-top: 3em;">
		<form action="find.php" method="post">
			<div class="item clearfix">
				<input value="" style="width:50%;float:left;background:none;border-color: #6b6b6b;" id="pw-phone"  name="phone" class="txt-input txtpd" placeholder="请输入注册手机号" type="text" />
       			<input id="btnSendCode2" style="width: 50%;float:left;background:#9a0000"  class="btn-login" name="btnSendCode2" type="button" value="发送验证码"/>
			</div>
			<div class="item clearfix">
		        <input name="yzm" style="background:none;border-color: #6b6b6b;margin-top: 0.9em;" class="txt-input txtpd" id="yzm" placeholder="请输入手机验证码" type="text" />
		     </div>
		     <div class="item">
		        <input value="" id="password" style="background:none;border-color: #6b6b6b;margin-top: 0.9em;" name="password" class="txt-input txtpd" placeholder="请输入重设密码" type="password" />
		     </div>			
			<div class="item item-btns" style="margin-top: 0.9em;"> 
			<input type="submit" value="提交" style="background:#9a0000" class="btn-login">
			</div>
		</form>
		    <div class="item item-login-option" style="margin-bottom: 0.9em;">
    <div style="width:100%;text-align:center"><a href="login.php" style="font-size:1em;color:#6b6b6b">已有帐号，点我登录</a></div>
    </div>
	</div>
</div>
<?php
	
if($_POST){
	$phone=guolv(trim($_POST['phone']));
	$pass=guolv(trim($_POST['password']));
  	$yzm=guolv(trim($_POST['yzm']));
    if($yzm==$_SESSION['yzm1']){
		$row=$mysql->query("select * from `userdata` where `phone`='{$phone}' limit 1");
		if($row){
			$mysql->execute("update `userdata` set `pass`='{$pass}' where `phone`='{$phone}'");
			echo "<script>alert('修改成功,请重新登录');location.href='login.php'</script>";
			exit;			
		}else{
			echo "<script>alert('手机号码错误');location.href='find.php'</script>";
			exit;		
		}
    }else{
	    echo "<script>alert('验证码错误');</script>";
	    exit;   
    }
}
$mysql->__destruct();
$mysql->close();
?>

</body>
</html>